package handledb;

public class PoolConfig {
    public String url;
    public String user;
    public String passwd;
    public String driver;
    public int maxsize = 10;  //最大通道数
    public int minsize = 5;  //最小通道数
    public int expansionSize = 5; // 每次扩容大小
    public long inteval = 1000 * 600;//每相隔一段时间清理一次通道  ms  默认10min
    public long waitTime = 1000 * 120;//等待最大时间，当超过所设定的时间资源将被强制释放   ms  默认值为2min
    public int attempts = 100;//当不能扩容时，又拿不到连接的时候尝试次数
    public long transactionTimeout = 1000l * 120; // 事务失效时间  打开事务后多长时间自动关闭该事务 ms 默认2min
    public String dbName;
    public int dbType;
    public String verifySql;
    public String beanName;

    public boolean showQuery = false;   // 日志打印查询语句
    public boolean showUpdate = false;  // 日志打印跟新语句

    public PoolConfig(){

    }
    public PoolConfig(String url, String user, String passwd, String driver) {
        dbName = url.split(":")[1];
        if ("oracle".equals(dbName)) {
            dbType = 1;
            verifySql = VerifySql.oracle;
        } else if ("mysql".equals(dbName)) {
            dbType = 2;
            verifySql = VerifySql.mysql;
        }
        this.url = url;
        this.user = user;
        this.passwd = passwd;
        this.driver = driver;
    }

    public PoolConfig(String url, String user, String passwd, String driver, String maxsize, String minsize, String expansionSize, String inteval, String waitTime, String attempts) {
        dbName = url.split(":")[1];
        System.out.println("poolConfig dbName:" + dbName);
        if ("oracle".equals(dbName)) {
            dbType = 1;
            verifySql = VerifySql.oracle;
        } else if ("mysql".equals(dbName)) {
            dbType = 2;
            verifySql = VerifySql.mysql;
        }
        this.url = url;
        this.user = user;
        this.passwd = passwd;
        this.driver = driver;
        setMaxsize(maxsize);
        setMinsize(minsize);
        setExpansionSize(expansionSize);
        setInteval(inteval);
        setWaitTime(waitTime);
        setAttempts(attempts);
    }
    public void setMaxsize(String maxsize) {
        if (maxsize != null) {
            this.maxsize = Integer.parseInt(maxsize);
        }
    }

    public void setMinsize(String minsize) {
        if (minsize != null) {
            this.minsize = Integer.parseInt(minsize);
        }
    }

    public void setExpansionSize(String expansionSize) {
        if (expansionSize != null) {
            this.expansionSize = Integer.parseInt(expansionSize);
        }
    }

    public void setInteval(String inteval) {
        if (inteval != null) {
            this.inteval = Long.parseLong(inteval);
        }
    }

    public void setWaitTime(String waitTime) {
        if (waitTime != null) {
            this.waitTime = Long.parseLong(waitTime);
        }
    }

    public void setAttempts(String attempts) {
        if (attempts != null) {
            this.attempts = Integer.parseInt(attempts);
        }
    }

    public void setTransactionTimeout(String transactionTimeout) {
        this.transactionTimeout = Long.parseLong(transactionTimeout);
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
        dbName = url.split(":")[1];
        if ("oracle".equals(dbName)) {
            dbType = 1;
            verifySql = VerifySql.oracle;
        } else if ("mysql".equals(dbName)) {
            dbType = 2;
            verifySql = VerifySql.mysql;
        }
    }

    public String getUser() {
        return user;
    }

    public void setUser(String user) {
        this.user = user;
    }

    public String getPasswd() {
        return passwd;
    }

    public void setPasswd(String passwd) {
        this.passwd = passwd;
    }

    public String getDriver() {
        return driver;
    }

    public void setDriver(String driver) {
        this.driver = driver;
    }

    public int getMaxsize() {
        return maxsize;
    }

    public void setMaxsize(int maxsize) {
        this.maxsize = maxsize;
    }

    public int getMinsize() {
        return minsize;
    }

    public void setMinsize(int minsize) {
        this.minsize = minsize;
    }

    public int getExpansionSize() {
        return expansionSize;
    }

    public void setExpansionSize(int expansionSize) {
        this.expansionSize = expansionSize;
    }

    public long getInteval() {
        return inteval;
    }

    public void setInteval(long inteval) {
        this.inteval = inteval;
    }

    public long getWaitTime() {
        return waitTime;
    }

    public void setWaitTime(long waitTime) {
        this.waitTime = waitTime;
    }

    public int getAttempts() {
        return attempts;
    }

    public void setAttempts(int attempts) {
        this.attempts = attempts;
    }

    public long getTransactionTimeout() {
        return transactionTimeout;
    }

    public void setTransactionTimeout(long transactionTimeout) {
        this.transactionTimeout = transactionTimeout;
    }

    public String getDbName() {
        return dbName;
    }

    public void setDbName(String dbName) {
        this.dbName = dbName;
    }

    public int getDbType() {
        return dbType;
    }

    public void setDbType(int dbType) {
        this.dbType = dbType;
    }

    public String getVerifySql() {
        return verifySql;
    }

    public void setVerifySql(String verifySql) {
        this.verifySql = verifySql;
    }

    public String getBeanName() {
        return beanName;
    }

    public void setBeanName(String beanName) {
        this.beanName = beanName;
    }

    public boolean isShowQuery() {
        return showQuery;
    }

    public void setShowQuery(boolean showQuery) {
        this.showQuery = showQuery;
    }

    public boolean isShowUpdate() {
        return showUpdate;
    }

    public void setShowUpdate(boolean showUpdate) {
        this.showUpdate = showUpdate;
    }

    @Override
    public String toString() {
        return "PoolConfig{" +
                "url='" + url + '\'' +
                ", user='" + user + '\'' +
                ", passwd='" + passwd + '\'' +
                ", driver='" + driver + '\'' +
                ", maxsize=" + maxsize +
                ", minsize=" + minsize +
                ", expansionSize=" + expansionSize +
                ", inteval=" + inteval +
                ", waitTime=" + waitTime +
                ", attempts=" + attempts +
                ", transactionTimeout=" + transactionTimeout +
                ", dbName='" + dbName + '\'' +
                ", dbType=" + dbType +
                ", verifySql='" + verifySql + '\'' +
                ", beanName='" + beanName + '\'' +
                ", showQuery=" + showQuery +
                ", showUpdate=" + showUpdate +
                '}';
    }
}
